package com.study.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.study.model.system.SysOperLog;
import com.study.model.vo.SysOperLogQueryVo;
import com.study.system.mapper.OperLogMapper;
import com.study.system.service.OperLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OperLogServiceImpl implements OperLogService {

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public void save(SysOperLog sysOperLog) {
        operLogMapper.insert(sysOperLog);
    }

    @Override
    public IPage<SysOperLog> getPage(Long page, Long limit, SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> queryPage = new Page<>(page,limit);
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getOperName();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
        if(!StringUtils.isNotEmpty(title)){
            wrapper.like("title",title);
        }
        if(!StringUtils.isNotEmpty(operName)){
            wrapper.like("oper_name",operName);
        }
        if (!StringUtils.isNotEmpty(createTimeBegin)){
            wrapper.ge("create_time",createTimeBegin);
        }
        if(!StringUtils.isNotEmpty(createTimeEnd)){
            wrapper.le("update_time",createTimeEnd);
        }
        Page<SysOperLog> pages = operLogMapper.selectPage(queryPage, wrapper);
        return pages;
    }
}
